home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK2.toast / Development Kits (Disc 2) / ScriptX / Draggable ScriptX Folders / utils / DTK / Examples / Custom Classes / anim.cls next >
Encoding:
Text File  |  1995-11-30  |  5.5 KB  |  191 lines  |  [TEXT/ttxt]

  1. --<<<
  2. format debug "--  Compiling Animation Class . . .\n" undefined undefined
  3.  
  4. function hideSprite     aData theTarget thePlayer->
  5. (
  6.     hide theTarget
  7. )
  8. function showSprite     aData theTarget thePlayer->
  9. (
  10.     show theTarget
  11. )
  12.  
  13. function loopMe aData theTarget thePlayer->
  14. (
  15.     gotoBegin thePlayer
  16. )
  17.  
  18. class Animation(ActionListPlayer)
  19. inst vars
  20.     autoStart
  21.     changeCastScript
  22.     moveCastScript
  23.     fps
  24. end
  25.  
  26. method changeRate self {class Animation} newValue->
  27. (
  28.     self.rate := newValue
  29. )
  30.  
  31. method init self {class Animation} #rest args #key lingo: dirInfo: currScene:
  32. ->(
  33.     local tFrame := findSXKey(lingo,"firstFrame")
  34.     local fNum := tFrame as integer
  35.     local firstFrame
  36.     if fNum = 0 then (
  37.         firstFrame := frameFromLabel(tFrame, dirInfo)
  38.     ) else (
  39.         firstFrame := fNum
  40.     )
  41.     tFrame := findSXKey(lingo,"lastFrame")
  42.     fNum := tFrame as integer
  43.     local lastFrame
  44.     if fNum = 0 then (
  45.         lastFrame := frameFromLabel(tFrame, dirInfo)
  46.     ) else (
  47.         lastFrame := fNum
  48.     )
  49.     local tVal := findSXKey(lingo,"firstChannel")
  50.     local firstChannel := tVal as integer
  51.     local tVal := findSXKey(lingo,"lastChannel")
  52.     local lastChannel := tVal as integer
  53.     format debug "Animation: Channel %1 thru %2 of frame %3 thru %4\n" \
  54.                     #(firstChannel, lastChannel, firstFrame, lastFrame ) \
  55.                     #(@unadorned, @unadorned, @unadorned, @unadorned)
  56.     self.autoStart := (findSXKey(lingo,"autoStart") = "yes")
  57.     local looped := (findSXKey(lingo,"looped") = "yes")
  58.     local sndChan := findSXKey(lingo,"sndChannel")
  59.     local useSound := (sndChan <> undefined) 
  60.     if sndChan = undefined then (
  61.         sndChan := 1
  62.     ) else (
  63.         sndChan := (sndChan as integer)
  64.     )
  65.     local sliderName := findSXKey(lingo,"slider")
  66.     local myActions := new ActionList
  67.     local initialTargets := #()
  68.     local score := dirInfo[@score]
  69.     local cast := dirInfo[@cast]
  70.     local frame := score[firstFrame]
  71.     local fps := frame[@tempoChannel][@tempo]
  72.     if fps = 0 do fps := dirInfo[@defaultFPS]
  73.     self.fps := fps
  74.     apply nextMethod self actionList:myActions scale:(fps) targetCount:((lastChannel - firstChannel) + 1) args
  75.     
  76.     local spriteArray := frame[@spriteChannels]
  77.     local castNum, sprite, relChan, relFrame, currTarget, changed
  78.     local workArray := new array
  79.     for c := firstChannel to lastChannel do (
  80.         relChan := (c - firstChannel) + 1
  81.         local currentTargetCast := undefined
  82.         local currentState := @unknown
  83.         for f := firstFrame to lastFrame do (
  84.             relFrame := (f - firstFrame) + 1
  85.             frame := score[f]
  86.             if c = firstChannel  and useSound do ( -- 1st time thru check soundChannel also
  87.                 local sndCast := frame[@soundChannels][sndChan]
  88.                 if sndCast <> 0 do (
  89.                     append myActions (new PlaySndAction sndStream:cast[sndCast] buffer:(100) targetNum:0 time:1)
  90.                     format debug "PlaySndAction for sound: %*\n" sndCast @unadorned
  91.                 )
  92.             )
  93.             sprite := frame[@spriteChannels][c]
  94.             castNum := sprite[@castIndex]
  95.             changed := frame[@changeArray][c] or f = firstFrame
  96.             if changed do (
  97.                 local actionRequested := @none
  98.                 if castNum <> 0 then (
  99.                     if currentTargetCast = castNum then (
  100.                         if currentState = @hidden do (
  101.                             actionRequested := @show
  102.                         )
  103.                     ) else if currentTargetCast = undefined then (
  104.                         currentTargetCast := castNum
  105.                         actionRequested := @initialize
  106.                     ) else (
  107.                         actionRequested := @change
  108.                     )
  109.                     currentState := @visible
  110.                 ) else (
  111.                     if currentState = @visible do (
  112.                         actionRequested := @hide
  113.                         currentState := @hidden
  114.                     )
  115.                 )
  116.                 local newAction := undefined
  117.                 case actionRequested of
  118.                     @initialize:
  119.                         (
  120.                         local currTarget := cast[castNum]
  121.                         currTarget.x := sprite[@x]
  122.                         currTarget.y := sprite[@y]
  123.                         local sten := currTarget.boundary
  124.                         case (sprite[@ink]) of
  125.                             @invisible:    (
  126.                                 sten.invisibleColor    := whiteColor
  127.                                 sten.matteColor     := undefined
  128.                                 )
  129.                             @matte:    (
  130.                                 sten.invisibleColor := undefined
  131.                                 sten.matteColor        := whiteColor
  132.                                 )
  133.                             @copy:        sten.invisibleColor := sten.matteColor := undefined
  134.                         end --case
  135.                         prepend currScene currTarget
  136.                         self.targets[relChan] := currTarget
  137.                         )
  138.                     @show:
  139.                         (
  140.                         newAction := new ScriptAction script: showSprite targetnum:relChan time:relFrame
  141.                         )
  142.                     @hide:
  143.                         (
  144.                         newAction := new ScriptAction script: hideSprite targetnum:relChan time:relFrame
  145.                         )
  146.                     @change:
  147.                         (
  148.                         local inks := #(@invisible:undefined,@matte:undefined)
  149.                         if sprite[@ink] = @invisible do setOne inks @invisible whiteColor
  150.                         if sprite[@ink] = @matte do setOne inks @matte whiteColor
  151.                         local newLoc := #(sprite[@x],sprite[@y]) as point
  152.                         newAction := new ChangeSpriteAction     targetnum:relChan \
  153.                                                     time:relFrame \
  154.                                                     target:(cast[castNum]) \
  155.                                                     inks:inks \
  156.                                                     location:newLoc
  157.                         )
  158.                 end --case
  159.                 if newAction <> undefined do append myActions newAction 
  160.             )
  161.         )
  162.     )
  163.     if looped do (
  164.         append myActions (new ScriptAction script:loopMe targetNum:0 time:( lastFrame - firstFrame +1))
  165.     )
  166.     if sliderName <> undefined do (
  167.         local sliderList := chooseAll currScene (obj type-> isAKindOf obj type) Slider
  168.         local connectTo := chooseOne sliderList (obj idValue-> obj.id = idValue) sliderName
  169.         if connectTo <> empty do (
  170.             connect connectTo values:#(0,2) target:self changeMethod:changeRate
  171.             setCurrValue connectTo 1
  172.         )
  173.     )
  174.     return self
  175. )
  176.  
  177. method xSetter self {class Animation} xValue->
  178. (
  179.     "xSetter ignored by Animation"
  180. )
  181. method ySetter self {class Animation} xValue->
  182. (
  183.     "ySetter ignored by Animation"
  184. )
  185. method boundaryGetter self {class Animation}->
  186. (
  187.     return undefined
  188. )
  189. #(Animation, #("autoStart"), #("initialTargetsGetter"))
  190. -->>>
  191.